﻿using System.Collections.Generic;
using ZSoft.Telegram.DataAccess.Abstractions;
using ZSoft.Telegram.Domain;
using ZSoft.Telegram.Services.Abstraction;
using ZSoft.Telegram.UI.ViewModels;
using System.Linq;
using System.Data.Entity;
using System.Threading.Tasks;

namespace ZSoft.Telegram.Services
{
    public class CategoryService : ICategoryService
    {
        private IRepository<Category> _repository;

        public CategoryService(IRepository<Category> repository)
        {
            this._repository = repository;
        }

        public IRepository<Category> Repository
        {
            get
            {
                return this._repository;
            }
        }
        
        public Task<List<CategoryViewModel>> GetAllCategoriesAsync()
        {
            return this._repository
                            .All()
                                .Select(c => new CategoryViewModel()
                                {
                                    Title = c.Title,
                                    Id = c.Id
                                }).ToListAsync();
        }
    }
}
